﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="IRepository.cs" company="Collaboris Ltd.">
//   Copyright (c) Collaboris Ltd. All rights Reserved.
// </copyright>
// <summary>
//   The i repository.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Collaboris.DataAccess
{
    #region Imports

    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;

    #endregion

    /// <summary>
    /// Represents the interface that needs to be implemented by all repository classes.
    /// </summary>
    /// <typeparam name="T">
    /// The data entity (business object) accepted\returned by the repository to write\read data to\from the data store
    /// </typeparam>
    /// <typeparam name="C">
    /// The criteria object accepted by the repository. 
    /// </typeparam>
    public interface IRepository<T, C>
    {
        /// <summary>
        /// Deletes a collection of Sharepoint list Items that conform to the 
        /// criteria.
        /// </summary>
        /// <param name="itemId">
        /// The item Id.
        /// </param>
        void Delete(long itemId);

        /// <summary>
        /// Deletes a collection of Sharepoint list Items that conform to the 
        /// criteria.
        /// </summary>
        /// <param name="criteria">
        /// The criteria.
        /// </param>
        void Delete(C criteria);

        /// <summary>
        /// Returns a new empty data entity.
        /// </summary>
        /// <returns>
        /// New data entity
        /// </returns>
        T CreateDataEntity();

        /// <summary>
        /// Returns a new empty Criteria.
        /// </summary>
        /// <returns>
        /// New data entity
        /// </returns>
        C CreateCriteria();

        /// <summary>
        /// Saves the Business object into the repository
        /// </summary>
        /// <param name="dataItem">
        /// </param>
        /// <returns>
        /// The Id of the item
        /// </returns>
        long Submit(T dataItem);

        /// <summary>
        /// Submits the specified data items.
        /// </summary>
        /// <param name="dataItems">The data items.</param>
        /// <returns> aList with the ids of the submitted items</returns>
        List<long> Submit(List<T> dataItems);        

        /// <summary>
        /// Returns the buisuness object with the specified id
        /// </summary>
        /// <param name="itemId">
        /// </param>
        /// <returns>
        /// </returns>
        T Load(long itemId);

        /// <summary>
        /// Returns the first business object that conforms to the criteria
        /// </summary>
        /// <param name="criteria">
        /// The criteria.
        /// </param>
        /// <returns>
        /// </returns>
        T Load(C criteria);

        /// <summary>
        /// Returns the first business object that conforms to the criteria
        /// </summary>
        /// <param name="query">
        /// The query.
        /// </param>
        /// <returns>
        /// </returns>
        List<T> LoadList(C query);

        /// <summary>
        /// Returns a data table with all the rows
        /// </summary>
        /// <returns>
        /// All the business objects on the data source
        /// </returns>
        DataTable LoadAllTable();

        /// <summary>
        /// Returns the first business object that conforms to the criteria
        /// </summary>
        /// <remarks>
        /// Use with caution because it can return a big amout of data.
        /// </remarks>
        /// <returns>
        /// All the business objects in the data source
        /// </returns>
        List<T> LoadAllList();

        /// <summary>
        /// Returns a data table with rows that conform to the criteria
        /// </summary>
        /// <remarks>
        /// Use with caution because it can return a big amout of data.
        /// </remarks>
        /// <param name="criteria">
        /// </param>
        /// <returns>
        /// All the business objects in the data source
        /// </returns>
        DataTable LoadTable(C criteria);
    }
}